<?php

namespace App\Trip\Train;

use Illuminate\Support\Str;

class TrainType
{
    /**
     * 根据车次号 获取火车类型描述
     * @param string $train_code
     * @return  string
     */
    static function getTrainTypeName(string $train_code): string
    {
        $types                = config('trip.train.type');
        $firstTrainCodeLetter = self::getTrainType($train_code);
        return $types[$firstTrainCodeLetter] ?? $types[0];
    }

    /**
     * 根据车次号 获取火车类型
     * @param string $train_code
     * @return  string
     */
    static function getTrainType(string $train_code): string
    {
        $firstTrainCodeLetter = $train_code[0];
        if (is_numeric($firstTrainCodeLetter)) {
            $firstTrainCodeLetter = 0;
        } else {
            $firstTrainCodeLetter = Str::upper($firstTrainCodeLetter);
        }
        return $firstTrainCodeLetter;
    }

    /**
     * 获取火车类型翻译
     * @param string $name
     * @param string $language
     * @return string
     */
    static function getTrainTypeNameTranslation(string $name, string $language = ''): string
    {
        return __("train_type.{$name}", [], $language);
    }
}